From fbf0c812711a22bfbddf52ee69f052cd46d515f8 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Tue, 12 Nov 2013 11:19:57 -0800 Subject: [PATCH] Rather than upsert module store, explicitly remove old value and then add new one Replacing the content of the module store might fail if the new contents would exceed the browser's localStorage size limit. To avoid clogging the browser with stale data, always remove the old value before attempting to set the new one. Change-Id: I91d01d845a1a633414b94cc02e142a9956955c9d --- resources/mediawiki/mediawiki.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 1f89792b2f..328ba836c5 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -1944,14 +1944,19 @@ var mw = ( function ( $, undefined ) { var timer; function flush() { - var data; + var data, key = mw.loader.store.getStoreKey(); if ( mw.loader.store.enabled !== true ) { return false; } mw.loader.store.prune(); try { + // Replacing the content of the module store might fail if the new + // contents would exceed the browser's localStorage size limit. To + // avoid clogging the browser with stale data, always remove the old + // value before attempting to set the new one. + localStorage.removeItem( key ); data = JSON.stringify( mw.loader.store ); - localStorage.setItem( mw.loader.store.getStoreKey(), data ); + localStorage.setItem( key, data ); } catch (e) {} } -- 2.20.1